<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>
        <#if questionnaire.type == '1'>
        扫码问卷
        <#else>
        对象问卷
        </#if>
    </title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport" content="width=device-width, user-scalable=no">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta name="apple-mobile-web-app-status-bar-style" content="default"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="format-detection" content="telephone=no"/>
    <link href="${s.base}/mobile/css/weui.min.css" rel="stylesheet"/>
    <link href="${s.base}/mobile/css/jquery-weui.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/cy-style.css" rel="stylesheet">
    <link href="${s.base}/mobile/lib/swiper/swiper.min.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/question/toup.css" rel="stylesheet">
    <link href="${s.base}/mobile/css/question/questionnaire.css" rel="stylesheet">
    <script type="text/javascript" src="${s.base}/mobile/js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="${s.base}/mobile/js/fontSize.js"></script>
    <!--<script type="text/javascript" src="${s.base}/mobile/js/window_port.js"></script>-->
</head>
<style>
    .weui-toast--text .weui-icon_toast{ display: none;}
    .weui-toast--text{font-size:18px;}
    .weui-toast--text{ padding:8px 16px; min-height: inherit; top:40%;width: auto;}
</style>
<body>
<div class="question"></div>
<section class="toup"  id="t1">
    <div class="swipers">
        <div class="con">
            <input type="hidden" id="tableId" value="${questionnaire.id}">
            <h1>${questionnaire.title}</h1>
            <p>创建时间：${createTime}</p>
            <p>参与时间：${currentTime}</p>
        </div>
        <#if questionnaire.status == '3'>
        <a href="javascript:;" class="jion"><div class="question-bot-xfbtn">参加本次调查</div></a>
        <#else>
        <a href="javascript:;" class="jion"><div class="question-bot-xfbtn">查看本次调查</div></a>
        </#if>
    </div>
</section>
<section class="toup" id="t2">
    <div class="swipers ">
        <!-- 上下 -->
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <#list questionnaire.subjectList as subject>
                    <#if subject.type == '1'>
                        <div class="swiper-slide swiper-no-swiping newquestionaire" dtype="${subject.type}" did="${subject.id}" dsort="${subject_index + 1}">
                            <div style="width: 100%; height: 100%; overflow-y: auto"><div class="scores">
                                <div class="f"><span class="fl qnsort">单选题</span><span class="subnum">${subject_index + 1}</span>、${subject.title }</div>
                                <div class="choose teacherwj">
                                    <#list subject.selectList as select>
                                        <div class="input">
                                            <label class="radio <#if subject.answer?index_of(select.id)!=-1>checked</#if>">
                                                <span class="radio-bg">${select.num }</span>
                                                <input type="radio" <#if questionnaire.status != '3'>disabled</#if> class="a-radio" <#if subject.answer?index_of(select.id)!=-1>checked="true"</#if>
                                                name="${subject.id}" dvalue="${select.id}" dscore="0" />

                                                ${select.title }
                                            </label>

                                        </div>
                                    </#list>
                                </div>
                                <div class="choose mart2em">

                                </div>
                            </div></div>
                        </div>
                    <#elseif subject.type == '2'>
                        <div class="swiper-slide swiper-no-swiping newquestionaire" dtype="${subject.type}" did="${subject.id}" dsort="${subject_index + 1}">
                            <div style="width: 100%; height: 100%; overflow-y: auto"><div class="scores">
                                <div class="f"><span class="fl qnsort">多选题</span><span class="subnum">${subject_index + 1}</span>、${subject.title }</div>
                                <div class="choose">
                                    <#list subject.selectList as select>
                                        <div class="input">
                                            <label class="checkBox"><input type="checkbox" <#if questionnaire.status != '3'>disabled</#if> <#if subject.answer?index_of(select.id)!=-1>checked="checked"</#if>
                                                name="${subject.id}" dvalue="${select.id}" dscore="0" />
                                            <span class="selectNum">${select.num }</span>${select.title }</label>
                                        </div>
                                    </#list>
                                </div>
                                <div class="choose mart2em">

                                </div>
                            </div>
                        </div></div>
                    <#else>
                        <div class="swiper-slide swiper-no-swiping newquestionaire" dtype="${subject.type}" did="${subject.id}" dsort="${subject_index + 1}">
                            <div style="width: 100%; height: 100%; overflow-y: auto">
                                <div class="scores">
                                    <div class="f"><span class="fl qnsort">简答题</span><span class="subnum">${subject_index + 1}</span>、${subject.title }</div>
                                    <div class="choose">
                                        <textarea rows="5" name="${subject.id}" <#if questionnaire.status != '3'>disabled</#if> placeholder="请输入内容">${subject.answer}</textarea>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </#if>
                </#list>
            </div>
            <!--<div class="preNexts">
                <div class="swiper-button-prev"><div class="pre"><span class="iconfont FS20">&#xe815;</span></div>上一题</div>
                <div class="swiper-button-next"><div class="next"><span class="iconfont FS20">&#xe658;</span></div>下一题</div>
            </div>-->
            <div class="question-bot-xfbtn">
                <div class="swiper-button-prev">
                    <i class="iconfont">&#xe673;</i>
                    上一题
                </div>
                <div class="swiper-button-next">
                    下一题
                    <i class="iconfont">&#xe8f7;</i>
                </div>
            </div>
        </div>
        <!-- 上下end -->
    </div>
</section>
<section class="toup" id="t3">
    <div class="swipers">
        <div class="con con1">
            <div class="smile">
                <h1>非常感谢您的配合!</h1>
                <!--<p>老师们会根据学生的反应情况来提升自己的教学质量。</p>-->
            </div>
        </div>
        <!--<a href="javascript:void(0);" id="pre" class="tijiao" style="margin:0.4rem 0 0.25rem 0;">未完成所有答题，返回答题</a>-->

        <#if questionnaire.status == '3'>
        <a href="javascript:void(0);" id="save"><div class="question-bot-xfbtn">提交调查</div></a>
        <#else>
        <a href="javascript:void(0);" id="save"><div class="question-bot-xfbtn">查看结束</div></a>
        </#if>
    </div>
</section>
<script type="text/javascript" src="${s.base}/mobile/lib/swiper/swiper.min.js" ></script>
<script type="text/javascript" src="${s.base}/mobile/js/jquery-weui.js"></script>
<script type="text/javascript" src="${s.base}/mobile/js/common.js"></script>
<script>
    var mySwiper  = new Swiper('.swiper-container', {
        pagination: '.swiper-pagination',
        //nextButton: '.swiper-button-next',
        //prevButton: '.swiper-button-prev',
        slidesPerView: 1,
        paginationClickable: true,
        spaceBetween: 30,
        noSwiping : true,
        loop: false
    });
    $("#t2,#t3").hide();
    $("a.jion").on("click",function(){
        $("#t1").hide();
        $("#t2").show();
    });
    var status = '${questionnaire.status}';
    //单选题
    $("span.radio-bg").bind("click",function(){
        if (status == "3"){
            $(this).parents(".choose").find("span.radio-bg").removeClass("checked");
            $(this).addClass("checked")
        }
    })
    $(".teacherwj .input .radio").bind("click",function(){
        if (status == "3"){
            $(".teacherwj .input .radio").removeClass("checked");
            $(this).addClass("checked");
        }
    })

    $('.swiper-button-prev').click(function(){
        var obj = $(".swiper-slide-active");
        var info = obj.find(".qnsort").html();
        // 判断是否是第一题
        if(info == "1"){
            return false;
        }
        mySwiper.slidePrev();
    });

    $('.swiper-button-next').click(function(){
        // 打印这道题目的信息
        var obj = $(".swiper-slide-active");
        var info = obj.find(".subnum").html();
        var type= obj.attr("dtype");
        var did = obj.attr("did");
        var dvalue="";
        var flag = true;
        if(type == 1){
            //每门课程
            dvalue=$("input[name='"+did+"']:checked").attr("dvalue");
            if(dvalue=="" || dvalue==null || dvalue ==undefined){
                $.toast("请完成第"+info+"题评价","text");
                flag=false;
                return false;
            }
        }
        //多选题
        if(type == 2){
            //每门课程
            $.each($("input[name='"+did+"']:checkbox:checked"),function(){
                dvalue=dvalue+$(this).attr("dvalue")+",";
            });

            if(dvalue=="" || dvalue==null || dvalue ==undefined){
                $.toast("请完成第"+info+"题评价","text");
                flag=false;
                return false;
            }
        }
        if(type == 3){
            dvalue=$("textarea[name='"+did+"']").val();
            //dvalue = dvalue.replace(/\s+/g,"");
            if(dvalue=="" || dvalue==null){
                $.toast("请完成第"+info+"题","text");
                flag=false;
                return false;
            }
        }

        if(!flag){
            mySwiper.allowSlideNext= false;//设置
            return false;
        }
        if(mySwiper .isEnd){
            $("#t2").hide();
            $("#t3").show();
        }
        mySwiper.slideNext();
    })

    /*$("#pre").on("click",function(){
        $("#t2").show();
        $("#t3").hide();
    });*/
</script>

<script>
    var token = '${token}';
    var applyId = '${applyId}';
    var status = '${questionnaire.status}';
    $("#save").on("click",function () {
        // 需要状态，当为结束时，直接跳出
        if(status == "4") {
            window.location.href = "/phone/question/questionList?token="+token+"&applyId="+applyId;
            return;
        }
        var tableId = $("#tableId").val();
        var savescoreobj = {};
        var scoreobj = [];
        var flag = true;
        $(".newquestionaire").each(function(info,object){
            info = $(this).find(".qnsort").html();
            var obj={};
            var type=$(this).attr("dtype");
            var did=$(this).attr("did");
            var dsort=$(this).attr("dsort");
            var dvalue="";
            var dscore=0;
            //单选题
            if(type == 1){
                dvalue=$("input[name='"+did+"']:checked").attr("dvalue");
                if(dvalue=="" || dvalue==null || dvalue ==undefined){
                    $.toast("请完成第"+info+"题评价","text");
                    flag=false;
                    return false;
                }
                dscore=dscore+parseFloat($("input[name='"+did+"']:checked").attr("dscore"));
            }
            //多选题
            if(type == 2){
                $.each($("input[name='"+did+"']:checkbox:checked"),function(){
                    dvalue=dvalue+$(this).attr("dvalue")+",";
                    dscore=dscore+parseFloat($(this).attr("dscore"));
                });

                if(dvalue=="" || dvalue==null || dvalue ==undefined){
                    $.toast("请完成第"+info+"题评价","text");
                    flag=false;
                    return false;
                }
                //清除最后一个逗号
                dvalue=(dvalue.slice(dvalue.length-1)==',')?dvalue.slice(0,-1):dvalue;
            }
            //问答题
            if(type == 3){
                dvalue=$("textarea[name='"+did+"']").val();
                //dvalue = dvalue.replace(/\s+/g,"");
                if(dvalue=="" || dvalue==null){
                    $.toast("请完成第"+info+"题","text");
                    flag=false;
                    return false;
                }
            }
            obj.subjectId=did;
            obj.applyId=applyId;
            obj.type=type;
            obj.selectId=dvalue;
            obj.score=dscore.toString();
            scoreobj.push(obj);
        });
        if(flag){
            savescoreobj.tableId = tableId;
            savescoreobj.subject = scoreobj;
            var data = {token:token,studentScoreJson:JSON.stringify(savescoreobj)};
            // console.log(data);
            $.fn.doPost('/phone/questionnaire/saveStudentScore', data, function (result) {
                if (result.code == 0){
                    window.location.href = "/phone/question/questionList?token="+token+"&applyId="+applyId;
                }else {
                    $.toast(result.data.msg,"text");
                }
            });
        }
    });
</script>
</body>
</html>
